package epin.fujiajun.sort.quick;

import epin.fujiajun.data.Array;
import epin.fujiajun.data.array.Number;

/**
 * Created by DELL on 2017/9/7.
 */
public class Primary extends Original {

    @Override
    public int partition(Array[] a, int lo, int hi) {
        int i = lo, j = hi + 1;
        Array v = a[lo];

        while (true){
            while (less(a[++i], v)){
                if (i == hi)
                    break;
            }

            while (less(v, a[--j])){
                if (j == lo)
                    break;
            }

            if (i >= j)
                break;

            exChange(a, i, j);
        }

        exChange(a, lo, j);
        return j;
    }

    public static void main(String[] args){
        new Primary().main(Number.createArray(100, 1000));
    }
}
